﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Infrastructure;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using OpenAuth.App.Report;
using OpenAuth.App.Request;
using OpenAuth.App.Response;

namespace OpenAuth.WebApi.Controllers
{
    /// <summary>
    /// 巡检到位率报表
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class InspectPlanReportController : ControllerBase
    {
        private InspectPlanReport _app;

        public InspectPlanReportController(InspectPlanReport app)
        {
            _app = app;
        }

        [HttpPost]
        public Response<IList<InspectPlanReportResp>> LoadData(InspectPlanReportReq req)
        {
            var result = new Response<IList<InspectPlanReportResp>>();
            try
            {
                result.Result = _app.LoadData(req);
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return result;
        }

        /// <summary>
        /// 获取报表的详情
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public TableData GetReportDetailList([FromQuery]InspectPlanReportReq request)
        {
            return _app.GetReportDetailList(request);
        }
    }
}